//
//  RootViewController.m
//  TableViewExample
//

#import "RootViewController.h"

@implementation RootViewController

- (void)viewDidLoad {
    [super viewDidLoad];

	self.title = @"Countries";
	arrCountries = [[NSArray alloc] initWithObjects:
					@"Australia",
					@"Canada",
					@"Germany",
					@"France",
					@"Great Britain",
					@"Italy",
					@"Japan",
					@"New Zealand",
					@"South Korea",
					@"United States", nil];
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return [arrCountries count];
}

- (UITableViewCell *)tableView:(UITableView *)tableView
		 cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    static NSString *CellIdentifier = @"Cell";
    
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc]
				 initWithStyle:UITableViewCellStyleDefault
				 reuseIdentifier:CellIdentifier] autorelease];
    }
    
	// Configure the cell.
	cell.textLabel.text = [arrCountries objectAtIndex:indexPath.row];
	NSString *imageName = [NSString stringWithFormat:@"%@.png",
						   [arrCountries objectAtIndex:indexPath.row]];
	cell.imageView.image = [UIImage imageNamed:imageName];

    return cell;
}

- (void)dealloc {
	[arrCountries release];
    [super dealloc];
}

@end

